package com.example.administrator.himalaya.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.adapter.MasterFragmentAdapter;
import com.example.administrator.himalaya.criticallies.DetailsFragment;
import com.example.administrator.himalaya.criticallies.ProgramFragment;

import java.util.ArrayList;
import java.util.List;

//专辑详情页
public class EnerMasterActivity extends AppCompatActivity implements TabLayout.OnTabSelectedListener {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> fragments;
    private MasterFragmentAdapter masterFragmentAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ener_master);
        tabLayout = (TabLayout) findViewById(R.id.tab_layout_eners_master);
        viewPager = (ViewPager) findViewById(R.id.view_pager_eners_master);
        fragments = new ArrayList<>();
        fragments.add(new ProgramFragment());
        fragments.add(new DetailsFragment());
        masterFragmentAdapter = new MasterFragmentAdapter(getSupportFragmentManager(),fragments,this);
        viewPager.setAdapter(masterFragmentAdapter);
        tabLayout.addOnTabSelectedListener(this);
        TabLayout.Tab tab = tabLayout.newTab();
        tab.setText("详情");
        tabLayout.addTab(tab);
        tab =tabLayout.newTab();
        tab.setText("节目");
        tabLayout.addTab(tab);
        tabLayout.setupWithViewPager(viewPager);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));


    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
}
